//
//  HRLocationViewModel.m
//  Hear
//
//  Created by mac on 2017/3/31.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRLocationViewModel.h"
#import "HRLocationModel.h"
@implementation HRLocationViewModel
- (void)putLoactionParam:(HRLocationRequetModel *)paramDict  isSeccess:(void(^)(BOOL isSeccess))isSeccess
{
    YTKApi *api = [YTKApi apiPutWithUrl:@"UserInfo/Put_UserCoordinate" parameter:paramDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithSuccess:^(YTKBaseRequest *request) {
            isSeccess(YES);
        }];
    }];
}

-(void)getCheckVersion:(NSDictionary *)param isForcedUpdate:(void(^)(BOOL isForcedUpdate))isForcedUpdate{
    YTKApi *api = [YTKApi apiGetWithUrl:@"System/Get_GetSounds" para:param];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithSuccess:^(YTKBaseRequest *request) {
            NSDictionary *dict = request.responseJSONObject;
            NSDictionary *contentDict = [dict[@"BodyContent"] jsonValueDecoded];//contentDict[@"IsShowCash"]
            [[NSUserDefaults standardUserDefaults] setObject:contentDict[@"IsShowCash"] forKey:@"IsShowCash"];
//            [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"IsShowCash"];

            if ([contentDict[@"IsForceUpdate"]intValue]){
                isForcedUpdate(YES);
            }else{
                isForcedUpdate(NO);
            }
        }];
    }];
}


-(void)postSaveUserContacts:(NSDictionary *)requstDict isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPostWithUrl:@"UserInfo/Post_SaveUserContacts" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            
            NSDictionary *dict = request.responseJSONObject;
            if ([dict[@"CodeStatus"] intValue] == 20000){
                isSeccess(YES);
            }else{
                isSeccess(NO);
            }
            // BodyContent
            
            
            
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            isSeccess(NO);
        }];
    }];
}

@end
